package com.xilihui.xlh.core.http;

import android.app.Activity;

import com.xilihui.xlh.core.app.BaseEntity;


/**
 * 2018/1/19.
 */

public abstract class HttpListSubscriber<T extends BaseEntity> extends HttpSubscriber<T> {

    private boolean isRefreshing;
    private final boolean isLoadingMore;

    public HttpListSubscriber(Activity activity, boolean isRefreshing, boolean isLoadingMore) {
        super(activity);
        this.isRefreshing = isRefreshing;
        this.isLoadingMore = isLoadingMore;
    }

    protected abstract void afterRefresh();

    protected abstract void afterLoadMore();

    protected abstract void checkEmpty(T t);

    protected abstract void checkRetry(String msg);

    @Override
    public void onNext(T t) {
        if (isRefreshing) {
            afterRefresh();
        } else if (isLoadingMore) {
            afterLoadMore();
        }
        super.onNext(t);
        checkEmpty(t);
    }

    @Override
    protected void onFail(String msg) {
        checkRetry(msg);
    }
}
